var e = [], t = [], a = {}, n = !1, p = '';

Component({
    properties: {
        isShowPrice: {
            type: String,
            value: "1"
        }
    },
    data: {
        _click_num: null,
        _click_line: null,
        _chooseDay: null,
        isHidden: !0,
        opacitys: 0,
        animationData2: {}
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    attached() {
        this.showTable();
      },
    
    // lifetimes: {
    //     attached: function() {},
    //     moved: function() {},
    //     detached: function() {}
    // },
    methods: {
        showTable(){
            for (var e = [], t = 0; t < 3; t++) {
                var a = new Object(), i = new Date(), r = new Date();
                if (i.getMonth() + 1 + t > 12) {
                    s = i.getMonth() + t - 12;
                    r.setFullYear(i.getFullYear() + 1, s, 1);
                } else {
                    var s = i.getMonth() + t;
                    r.setFullYear(i.getFullYear(), s, 1);
                }
                var o = this.getOnMonthDaysPrice(r, t);
                n && (o = this.getOnMonthDaysPrice1(r, t)), a.year = r.getFullYear(), a.month = r.getMonth() + 1, 
                a.dates = o, e.push(a);
            }
            this.setData({
                lines: e
            });
            console.log(e)
        },
        showDate: function() {
            var e = wx.createAnimation({
                duration: 400,
                timingFunction: "ease"
            }), t = wx.createAnimation({
                duration: 400,
                timingFunction: "ease"
            });
            this.setData({
                isHidden: !1
            }), e.translateY(-450).step(), t.opacity(1).step(), this.setData({
                animationData: e.export(),
                animationData2: t.export()
            });
        },
        hiddenDate: function() {
            var e = this, t = wx.createAnimation({
                duration: 400,
                timingFunction: "ease"
            }), a = wx.createAnimation({
                duration: 400,
                timingFunction: "ease"
            });
            this.animation = t, t.translateY(450).step(), a.opacity(0).step(), setTimeout(function() {
                e.setData({
                    isHidden: !0,
                    opacitys: 0
                });
            }, 400), this.setData({
                animationData: this.animation.export(),
                animationData2: a.export()
            });
        },
        changePrice: function() {
            var e = t, t_price = p, a = this.data.lines;
            for (var n in a) {
                var i = a[n].year, r = a[n].month + "";
                r.length < 2 && (r = "0" + r);
                for (var s in a[n].dates) {
                    var o = a[n].dates[s].date + "";
                    1 == o.length && (o = "0" + o);
                    var c = i + "-" + r + "-" + o;
                    // console.log(c)
                    for (var u in e) {
                        if (e[u] == c) {
                            a[n].dates[s].ddd = e[u], a[n].dates[s].price = "￥" + t_price;
                            break;
                        }
                   }
                }
            }
            this.setData({
                lines: a
            });
            console.log(a)
        },
        getOnMonthDaysPrice: function(e, t) {
            var a = [], n = new Object(), i = new Object();
            i = {}, (n = {}).value = e.getFullYear(), n.isLeapyear = this.isLeapyear(n), i.value = e.getMonth() + 1, 
            i.totalDay = this.totalDay(i, n);
            var r = new Date();
            r.setFullYear(n.value, i.value - 1, 1);
            for (var s = r.getDay(), o = 0; o < s; o++) {
                var c = new Object();
                c.date = "", c.price = "", a.push(c);
            }
            for (o = 1; o <= i.totalDay; o++) {
                var u = new Object();
                u.date = o, u.price = "", a.push(u);
            }
            for (var l = a.length % 7, o = 0; o < 7 - l; o++) {
                var h = new Object();
                h.date = "", h.price = "", a.push(h);
            }
            return a;
        },
        getOnMonthDaysPrice1: function(e, t) {
            var a = [], n = new Object(), i = new Object();
            i = {}, (n = {}).value = e.getFullYear(), n.isLeapyear = this.isLeapyear(n), i.value = e.getMonth() + 1, 
            i.totalDay = this.totalDay(i, n);
            var r = new Date();
            r.setFullYear(n.value, i.value - 1, 1);
            for (var s = r.getDay(), o = 0; o < s; o++) {
                var c = new Object();
                c.date = "", c.price = "", a.push(c);
            }
            for (o = 1; o <= i.totalDay; o++) {
                var u = new Object();
                0 == t ? o < new Date().getDate() ? (u.date = o, u.price = "") : (new Date().getDate(), 
                u.date = o, u.price = " ") : (u.date = o, u.price = " "), a.push(u);
            }
            for (var l = a.length % 7, o = 0; o < 7 - l; o++) {
                var h = new Object();
                h.date = "", h.price = "", a.push(h);
            }
            return a;
        },
        getOnMonthDays: function(e, t) {
            var a = [], n = new Object(), i = new Object();
            i = {}, (n = {}).value = e.getFullYear(), n.isLeapyear = this.isLeapyear(n), i.value = e.getMonth() + 1, 
            i.totalDay = this.totalDay(i, n);
            var r = new Date();
            r.setFullYear(n.value, i.value - 1, 1);
            for (var s = r.getDay(), o = 0; o < s; o++) {
                var c = new Object();
                c.date = "", c.price = "", a.push(c);
            }
            for (o = 1; o <= i.totalDay; o++) {
                var u = new Object();
                0 == t ? o < new Date().getDate() ? (u.date = o, u.price = "") : (new Date().getDate(), 
                u.date = o, u.price = "￥50") : (u.date = o, u.price = "￥50"), a.push(u);
            }
            for (var l = a.length % 7, o = 0; o < 7 - l; o++) {
                var h = new Object();
                h.date = "", h.price = "", a.push(h);
            }
            return a;
        },
        isLeapyear: function(e) {
            return this.value % 4 == 0 && this.value % 100 != 0 || this.value % 400 == 0;
        },
        totalDay: function(e, t) {
            var a;
            return a = 1 == e.value || 3 == e.value || 5 == e.value || 7 == e.value || 8 == e.value || 10 == e.value || 12 == e.value ? 31 : 2 == e.value ? t.isLeapyear ? 29 : 28 : 30, 
            a;
        },
        chooseDate: function(e) {
            var t = e.currentTarget.dataset.index, i = parseInt(e.currentTarget.id), r = this.data.lines[t].year, s = this.data.lines[t].month, o = this.data.lines[t].dates[i].date, c = this.data.lines[t].dates[i].price, u = this.data.lines[t].dates[i].ddd;
            n ? (a = {
                year: r,
                month: s,
                day: o,
                ddd: u = r + "-" + s + "-" + o
            }, this.onTap(), this.hiddenDate()) : c && "" != c && (a = {
                year: r,
                month: s,
                day: o,
                ddd: u
            }, this.onTap(), this.hiddenDate()), this.setData({
                _click_num: i,
                _click_line: t
            });
        },
        onTap: function() {
            var e = {
                date: a
            }, t = {};
            this.triggerEvent("myevent", e, t);
        },
        setPrice: function(s,a) {
          p = s, e = a, t = a, this.changePrice();
        },
        setNoPrice: function() {
            n = !0;
        }
    }
});